<?php

namespace Muyuxuanpay\threePay;

class Pay
{
    public static function getPayManager($config=[],$type='official')
    {
        $types = explode('.',$type);
        $className = __NAMESPACE__.'\\src\\'.$types[0].'\\Manager';
        if(!class_exists($className)){
            throw new \Exception('支付类型错误');
        }
        if(count($types)==1){
            return new $className($config);
        }elseif (count($types)==2){
            $className2 = __NAMESPACE__.'\\src\\'.$types[0].'\\'.$types[1].'\\Pay';
            if(!class_exists($className2)){
                $className2 = __NAMESPACE__.'\\src\\'.$types[0].'\\'.$types[1].'Payment\\Pay';
                if(!class_exists($className2)){
                    throw new \Exception('支付类型错误');
                }
            }
            return new $className2($config);
        }
    }
}